import java.util.Arrays;
import java.util.Comparator;

//comparable接口比较

/**class Student implements Comparable<Student>{    //comparable比较接口
    public int age;
    public String name;
    public double score;

    public Student(int age, String name, double score) {
        this.age = age;
        this.name = name;
        this.score = score;
    }

    public Student() {
    }

    @Override
    public String toString() {
        return "student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    //谁调用这个方法谁就是这个this
    @Override
    public int compareTo(Student o) {
       // return this.age-o.age;
        return o.age-this.age;

    }
}*/


                             //comparator(比较器)接口比较

class Student {
    public int age;
    public String name;
    public double score;

    public Student(int age, String name, double score) {
        this.age = age;
        this.name = name;
        this.score = score;
    }

    public Student() {
    }

    @Override
    public String toString() {
        return "student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
       }
    }
class AgeComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}

class ScoreComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return (int)(o2.score-o1.score);
    }
}

class NameComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}


    public class packageDemo {
    public static void main2(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student(18,"xie",95.5);
        students[1] = new Student(22,"jiang",90);
        students[2] = new Student(20,"li",97.5);
        AgeComparator ageComparator = new AgeComparator();
        ScoreComparator scoreComparator = new ScoreComparator();
        NameComparator nameComparator = new NameComparator();

        Arrays.sort(students,nameComparator);

        System.out.println(Arrays.toString(students));


    }







    public static void main1(String[] args) {
        int [] array = {1,3,2,4,5};
        System.out.println(Arrays.toString(array));
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }
}
